<?php

namespace app\admin\behavior;

use app\admin\model\DormitoryDorm;
use think\Config;
use think\Lang;

class Common
{
    public function qrcodeInit()
    {
        set_time_limit(0);
        while (true) {
            $dorm_list = DormitoryDorm::where('qrcode', '')->field('id')->order('id', 'desc')->limit(20)->select();

            if (!$dorm_list) break;

            $update_data = [];
            foreach ($dorm_list as $key => $value) {
                $qrcode = DormitoryDorm::generateQrcode($value['id']);
                $update_data[] = [
                    'id'     => $value['id'],
                    'qrcode' => $qrcode,
                ];
            }
            if ($update_data) {
                $dorm = new DormitoryDorm;
                $dorm->isUpdate(true)->saveAll($update_data);
            }

        }
    }
}
